package com.songshuai.webapi.baseapi.enumerations;


public enum ResultStatus {
    // -1为通用失败（根据ApiResult.java中的构造方法注释而来）
    FAIL(-1, "请重新登录获取token"),
    FAILOfficial(1, "common fail"),
    // 0为成功
    SUCCESS(0, ""),

    ERROR_PIC_FILE(3,"非法图片文件"),
    ERROR_PIC_UPLOAD(4,"图片上传失败"),
    ERROR_RECORD_NOT_FOUND(5, "没有找到对应的数据"),
    ERROR_MAX_PAGE_SIZE(6, "请求记录数超出每次请求最大允许值"),
    ERROR_CREATE_FAILED(7,"新增失败"),
    ERROR_UPDATE_FAILED(8,"修改失败"),
    ERROR_DELETE_FAILED(9,"删除失败"),
    ERROR_SEARCH_FAILED(10,"查询失败"),
    ERROR_COUNT_FAILED(11,"查询数据总数失败"),
    ERROR_STRING_TO_OBJ(12,"字符串转java对象失败"),
    ERROR_INVALID_ARGUMENT(13,"参数不合法"),
    ERROR_UPDATE_NOT_ALLOWED(14,"更新失败：%s"),
    ERROR_DUPLICATED_DATA(15,"数据已存在"),
    ERROR_UNKNOWN_DATABASE_OPERATION(16,"未知数据库操作失败，请联系管理员解决"),
    ERROR_COLUMN_UNIQUE(17,"字段s%违反唯一约束性条件"),
    ERROR_FILE_DOWNLOAD(18,"文件下载失败"),
    ERROR_FILE_UPLOAD(19,"文件上传失败"),
    ERROR_RELATE_FAILED(20,"关联失败"),
    ERROR_IS_EXIST(21,"已存在"),
    ERROR_NO_PRIVILEGE(22,"用户无操作权限"),
    ERROR_REPEAT_OPERATION(23,"请勿重复操作"),
    //100-511为http 状态码
    // --- 4xx Client error ---
    HTTP_STATUS_BAD_REQUEST(400, "Bad Request"),
    HTTP_STATUS_UNAUTHORIZED(401, "Unauthorized"),
    HTTP_STATUS_PAYMENT_REQUIRED(402, "Payment Required"),
    HTTP_STATUS_FORBIDDEN(403, "Forbidden"),
    HTTP_STATUS_NOT_FOUND(404, "Not Found"),
    HTTP_STATUS_METHOD_NOT_ALLOWED(405, "Method Not Allowed"),
    HTTP_STATUS_NOT_ACCEPTABLE(406, "Not Acceptable"),
    HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED(407, "Proxy Authentication Required"),
    HTTP_STATUS_REQUEST_TIMEOUT(408, "Request Timeout"),
    HTTP_STATUS_CONFLICT(409, "Conflict"),
    HTTP_STATUS_GONE(410, "Gone"),
    HTTP_STATUS_LENGTH_REQUIRED(411, "Length Required"),
    HTTP_STATUS_PRECONDITION_FAILED(412, "Precondition Failed"),
    HTTP_STATUS_PAYLOAD_TOO_LARGE(413, "Payload Too Large"),
    HTTP_STATUS_URI_TOO_LONG(414, "URI Too Long"),
    HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"),
    HTTP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE(416, "Requested range not satisfiable"),
    HTTP_STATUS_EXPECTATION_FAILED(417, "Expectation Failed"),
    HTTP_STATUS_IM_A_TEAPOT(418, "I'm a teapot"),
    HTTP_STATUS_UNPROCESSABLE_ENTITY(422, "Unprocessable Entity"),
    HTTP_STATUS_LOCKED(423, "Locked"),
    HTTP_STATUS_FAILED_DEPENDENCY(424, "Failed Dependency"),
    HTTP_STATUS_UPGRADE_REQUIRED(426, "Upgrade Required"),
    HTTP_STATUS_PRECONDITION_REQUIRED(428, "Precondition Required"),
    HTTP_STATUS_TOO_MANY_REQUESTS(429, "Too Many Requests"),
    HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE(431, "Request Header Fields Too Large"),

    // --- 5xx Server error ---
    HTTP_STATUS_INTERNAL_SERVER_ERROR(500, "系统错误"),
    HTTP_STATUS_NOT_IMPLEMENTED(501, "Not Implemented"),
    HTTP_STATUS_BAD_GATEWAY(502, "Bad Gateway"),
    HTTP_STATUS_SERVICE_UNAVAILABLE(503, "Service Unavailable"),
    HTTP_STATUS_GATEWAY_TIMEOUT(504, "Gateway Timeout"),
    HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED(505, "HTTP Version not supported"),
    HTTP_STATUS_VARIANT_ALSO_NEGOTIATES(506, "Variant Also Negotiates"),
    HTTP_STATUS_INSUFFICIENT_STORAGE(507, "Insufficient Storage"),
    HTTP_STATUS_LOOP_DETECTED(508, "Loop Detected"),
    HTTP_STATUS_BANDWIDTH_LIMIT_EXCEEDED(509, "Bandwidth Limit Exceeded"),
    HTTP_STATUS_NOT_EXTENDED(510, "Not Extended"),
    HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED(511, "Network Authentication Required"),
    PANGU_USERINFO_EEROR(512,"pangu user info error"),

    // --- 8xx common error ---
    EXCEPTION(800, "exception"),
    INVALID_PARAM(801, "invalid.param"),
    INVALID_PRIVI(802, "invalid.privi"),

    //1000以内是系统错误，
    NO_LOGIN(1000,"没有登录"),
    CONFIG_ERROR(1001,"参数配置表错误"),
    USER_EXIST(1002,"用户名已存在"),
    USERPWD_NOT_EXIST(1003,"用户名不存在或者密码错误"),
    ROLE_NAME_REPEAT(1004,"角色名称重复"),
    ROLE_START_TIME_ERROR(1005,"角色开始时间不能大于结束时间"),
    CAMPUS_ID_NO_EXIST(1006,"校区不存在"),
    DATE_FORMAT_ERROR(1007,"时间格式错误"),
    ROLE_USER_EXIST_ERROR(1008,"该角色下已存在用户，请先清除用户"),
    UPLOAD_DATA_NO_EXIST_ERROR(1009,"上传数据已不存在，请重新操作"),
    UPLOAD_FILE_TOO_BIG(1010,"仅支持1M以内的文件"),
    UPLOAD_FILE_FORMAT__ERROR(1011,"上传文件格式不正确"),
    UPLOAD_FILE_NO_RECORD__ERROR(1012,"上传文件无有效数据"),
    EXPORT_FILE_OSS_SERVER__ERROR(1013,"导出文件，服务器发生异常"),
    UPLOAD_FILE_NO_EXIST__ERROR(1014,"请选择上传文件"),
    UPLOAD_FILE_SUFFIX__ERROR(1015,"仅支持.xls和.xlsx格式的文件"),
    GET_TOKEN_ERROR(1016,"获取token失败"),
    UNIDENTIFIABLE_APPID_ERROR(1017,"appid无法识别"),
    USER_INFO_ENCRYPTED_DATA_ERROR(1018,"用户信息密钥或加密串为空"),
    SESSION_KEY_FAILURE(-2,"session_key已失效，请重新获取token"),
    NEED_GET_PERMISSION(-3,"需要授权登录"),
    ERROR_BIND_SALES_INFO(-4,"盘古信息：身份信息不正确"),
    ERROR_BIND_CUST_INFO(-6,"盘古返回不正确"),
    ERROR_DECRYPT_MOBILE(-5,"解密手机号失败");


    private int code;
    private String msg;

    ResultStatus(int code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public static int getCode(String define){
        try {
            return ResultStatus.valueOf(define).code;
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            return FAIL.getErrorCode();
        }
    }

    public static String getMsg(String define){
        try {
            return ResultStatus.valueOf(define).msg;
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            return FAIL.getErrorMsg();
        }
    }

    public static String getMsg(int code){
        for(ResultStatus err : ResultStatus.values()){
            if(err.code==code){
                return err.msg;
            }
        }
        return "errorCode not defined ";
    }

    public int getErrorCode(){
        return code;
    }

    public String getErrorMsg(){
        return msg;
    }
}
